// pages/assembly/assembly6/assembly6.js
Page({

   /**
    * 页面的初始数据
    */
   data: {
      strokeWidth: 1,
      fontSize: 10,
      activeColor: "#269021",
      sliderEventList: {
         flag: false,
         infoList: [{
            eventId: "percent",
            min: 0,
            max: 100,
            dic: "显示的百分比（0~100%）",
            company: "", //用于添加数值后缀单位
            color: "" //用于添加颜色前缀
         }, {
            eventId: "borderRadius",
            min: 0,
            max: 10,
            dic: "进度条的圆角大小（0~10）",
            company: "",
            color: ""
         }, {
            eventId: "fontSize",
            min: 10,
            max: 50,
            dic: "右侧百分比字体大小（10~50）",
            company: "",
            color: ""
         }, {
            eventId: "strokeWidth",
            min: 1,
            max: 50,
            dic: "进度条线的宽度（10~50）",
            company: "",
            color: ""
         }, {
            eventId: "activeColor",
            min: "000000",
            max: "999999",
            dic: "已选择的进度条的颜色",
            company: "",
            color: "#"
         }, {
            eventId: "backgroundColor",
            min: "000000",
            max: "999999",
            dic: "未选择的进度条的颜色",
            company: "",
            color: "#"
         }]
      },
      switchEventList: {
         flag: false,
         infoList: [{
            eventId: "active",
            dic: "进度条从左往右的动画",
            checkedFalse: false, // 未选中时的值
            checkedTrue: true // 选中时的值，
         }, {
            eventId: "actionMode",
            dic: "进度条改变时的样式（backwards，forwards）,感觉这个属性没有起到应有的作用",
            checkedFalse: "backwards", // 未选中时的值
            checkedTrue: "forwards" // 选中时的值，
         }]
      }
   },
   bindToSwitch(event) {
      this.data.switchEventList.flag || fun(this)

      if (!event) return;
      var name = event.currentTarget.dataset.typeid;
      this.data.switchEventList[name](event);
      console.log("~~~" + this.data.active)

      function fun(_this) {
         var infoList = _this.data.switchEventList.infoList
         // console.log("~~~" + infoList)
         for (var i = 0; i < infoList.length; i++) {
            (function (item) {
               _this.data.switchEventList[item.eventId] = function (event) {
                  // console.log(event)
                  _this.setData({
                     [item.eventId]: event.detail.value ? item.checkedTrue : item.checkedFalse
                  })
               }
            })(infoList[i])
         }
         _this.data.switchEventList.flag = true;
      }
   },


   bindTo(event) {
      this.data.sliderEventList.flag || fun(this)

      var name = event.currentTarget.dataset.typeid;
      this.data.sliderEventList[name](event);

      function fun(_this) {
         var infoList = _this.data.sliderEventList.infoList
         console.log("~~~" + infoList)
         for (var i = 0; i < infoList.length; i++) {
            (function (item) {
               _this.data.sliderEventList[item.eventId] = function (event) {
                  // console.log(event)
                  // console.log(item.color + event.detail.value.toString() + item.company)
                  _this.setData({
                     [item.eventId]: item.color + event.detail.value.toString() + item.company
                  })
               }
            })(infoList[i])
         }
         _this.data.sliderEventList.flag = true;
      }
   },

   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {},


   /**
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady: function () {

   },

   /**
    * 生命周期函数--监听页面显示
    */
   onShow: function () {

   },

   /**
    * 生命周期函数--监听页面隐藏
    */
   onHide: function () {

   },

   /**
    * 生命周期函数--监听页面卸载
    */
   onUnload: function () {

   },

   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh: function () {

   },

   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {

   },

   /**
    * 用户点击右上角分享
    */
   onShareAppMessage: function () {

   }
})